Matrix := Object clone
Matrix dim := method(
    x,y,
    self data := list
    for (i,1,y,
        self data append(List setSize(x) clone) //不加clone会出错
    )
    List setSize(0) //修改回来list的默认大小
)
Matrix set := method(
    x,y,z, 
    self data at(y-1) atPut(x-1,z)
)
Matrix get := method(
    x,y,self data at(y-1) at(x-1)
)
mat := Matrix clone
mat dim(3,2)
mat data println
mat set(1,1,13)
mat data println
mat get(1,1) println

Matrix transform := method(
    y := self data size
    x := self data at(0) size
    newdata := Matrix clone
    newdata data := list
    for (i,1,x,
        tmp := list
        for (j,1,y,
            b := self get(i,j)
            tmp append(b)
        )
        newdata data append(tmp)
    )
    newdata
)

new_matrix := mat transform
new_matrix data println

Matrix save := method(
    f := File with("matrix.txt")
    f openForUpdating
    for(i, 0, (self data size)-1 ,
        f write(self data at(i) join(" "), "\n")
    );
    f close
)

mat save

Matrix read := method(
    filename,
    f := File with(filename)
    f open
    self data := list
    f foreachLine(i, line, 
        row := line split
        newrow := list
        self data append(row map(x, if (x == "nil", "nil", x asNumber)))
    )
)

matread := Matrix clone read("matrix.txt")
matread println